package com.pb.poem.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;

import com.pb.poem.dao.PoemDao;
import com.pb.poem.dao.impl.PoemDaoImpl;
import com.pb.poem.entity.Poem;
import com.pb.poem.service.impl.PoemServiceImpl;
import com.pb.poem.util.Page;

public class MyPoem extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
  
    public MyPoem() {
        super();
         
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter pw = response.getWriter(); 
		
		PoemServiceImpl poemService=new PoemServiceImpl();
		PoemDao poemDao=new PoemDaoImpl();
		poemService.setPoemDao(poemDao);
		
        int id=Integer.parseInt(request.getParameter("pId"));
        String uid=(String)request.getSession().getAttribute("uid");
 
		List<Poem> list=poemService.getonePagePoemList(id, uid);
		for(Poem poem:list){
			String p=poem.getContent();
			p=p.replaceAll("，", "，<br />");
			p=p.replaceAll("。", "。<br />");
			poem.setContent(p);
		}
				
		JSONArray ja=new JSONArray(list);
		String json = ja.toString();       
		pw.print(json);  
		pw.flush();  
		pw.close(); 
	}

}
